﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Threading.Tasks;
using ALMDDD.Application.Interfaces;
using ALMDDD.Application.ViewModels.SysUser;
using ALMDDD.AspNetCore.Redis;
using ALMDDD.Domain.Model;
using Newtonsoft.Json;
using Microsoft.AspNetCore.Mvc;

// For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860

namespace ALMDDD.API.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class UserController : Controller
    {
        private ISysUserService _sysUserService;
        public UserController(ISysUserService sysUserService)
        {
            _sysUserService = sysUserService;
        }
        // GET: /<controller>/
        [HttpGet("UserLoginCheck")]
        public string UserLoginCheck(string userName, string pass)
        {
            string result = null;
            try
            {
                if (OperateWithRedis.KeyExpireFun("UserKey:" + userName, TimeSpan.FromMinutes(20)))
                {
                    Expression<Func<Sys_User, bool>> exp = c => c.UserId == userName && c.PassWord == pass;
                    SysUserViewModel list = _sysUserService.GetMany(exp);

                    SysUserListsVO ss = _sysUserService.GetUserRoles(Guid.Parse("5F77AF22-33F1-429E-AB51-3A3F46B65734"));

                    OperateWithRedis.StringSetFun("UserKey:" + userName, JsonConvert.SerializeObject(ss), 0, TimeSpan.FromMinutes(20));
                     JsonConvert.SerializeObject(ss);

                }

            }
            catch (Exception ex)
            {
                return "";
            }

        }
    }

}
